<template>
    <el-upload class="upload-demo" drag action="/admin/v1/upload/oss/file" multiple :data="data" :name="name"
        :headers="{ token }" :on-success="uploadSuccess" :on-error="uploadError">
        <el-icon class="el-icon--upload">
            <upload-filled />
        </el-icon>
        <div class="el-upload__text">
            Drop file here or <em>click to upload</em>
        </div>
        <template #tip>
            <div class="el-upload__tip">
                jpg/png files with a size less than 500kb
            </div>
        </template>
    </el-upload>
</template>

<script setup lang="ts">
import { UploadFilled } from '@element-plus/icons-vue'
import cache from '@/utils/cache.js'
import { toast } from '@/utils/utils.js'
var token = cache.session.get("token");
defineProps({
    data: {
        type: Object,
        default: { dir: "imagebox" }
    },
    name: {
        type: String,
        default: "file"
    }
})


// 驱动事件
var emit = defineEmits(["success"]);

const uploadSuccess = (response) => {
    if (response.status == "101100607") {
        toast(response.msg);
        return;
    }
    emit("success", response);
}

const uploadError = (error) => {
    toast(error.msg);
}

</script>
